package com.dut.bbs.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

public class NetWorkAvailable {
	public static boolean goodNet(Context context)
    {  
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);    
        NetworkInfo networkinfo = manager.getActiveNetworkInfo();    
        if (networkinfo == null || !networkinfo.isAvailable()) {    
            return false;  
        }  
        return true;  
    }
	public static boolean goodNetIp(){
		return true;
//		URL infoUrl = null;
//		InputStream inStream = null;
//		boolean flag = false;
//		try{
//			infoUrl = new URL(URLConstant.IP_QUERY);
//			HttpURLConnection httpConnection = (HttpURLConnection)infoUrl.openConnection();
//			int responseCode = httpConnection.getResponseCode();
//			if(responseCode == HttpURLConnection.HTTP_OK)
//			{
//			inStream = httpConnection.getInputStream();
//			BufferedReader reader = new BufferedReader(new InputStreamReader(inStream,"gb2312"));
//			StringBuilder strber = new StringBuilder();
//			String line = null;
//			while ((line = reader.readLine()) != null)
//			strber.append(line + "\n");
//			inStream.close();
//			httpConnection.disconnect();
//			//从反馈的结果中提取出IP地址
////			int start = strber.indexOf("[");
////			int end = strber.indexOf("]", start + 1);
////			line = strber.substring(start + 1, end);
//			String str = new String(strber);
//			if(str.contains("大连理工大学"))
//				flag = true;
//			}
//		}catch(Exception e){
//			Log.v("NETIP", e.getMessage());
//		}
//		return flag;
	}
}
